﻿Public Class propriceoncontact
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Private PRDCODE = Nothing
    Private STATUS = Nothing

    Property PRDCODE_ As Integer
        Get
            Return PRDCODE
        End Get
        Set(value As Integer)
            PRDCODE = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    'proonproduct
    Private POPID = Nothing
    Private PROID = Nothing
    Private POCID = Nothing
    Private ODISCOUNT = Nothing
    Private IDISCOUNT = Nothing
    Private selectProonproduct = ""

    'prdprice
    Private PRCID = Nothing
    Private MTRGTID = Nothing
    Private STRGTID = Nothing
    Private SBRGTID = Nothing
    Private F_PRO = Nothing
    Private OPDRC = Nothing
    Private IPDRC = Nothing
    Private STDATE = Nothing
    Private ENDATE = Nothing
    Private selectPrdprice = "SELECT a.`prdcode` AS 'รหัสสินค้า', a.`proid` AS 'รหัสโปรโมชั่น', c.`proname` AS 'ชื่อโปรโมชั่น', b.`odiscount` AS 'ส่วนลดผู้ป่วยนอก', b.`idiscount` AS 'ส่วนลดผู้ป่วยใน', a.`opdprc` AS 'ราคาผู้ป่วยนอก', a.`ipdprc` AS 'ราคาผู้่ป่วยใน', a.`stdate` AS 'วันที่เริ่มต้นใช้ราคา', a.`endate` AS 'วันที่สิ้นสุดการใช้ราคา', a.`status` AS 'สถานะการเปิดใช้งาน' FROM prdprice a JOIN proonproduct b ON a.prdcode = b.prdcode JOIN maspromotion c ON a.proid = c.proid WHERE a.f_pro = '1'"

    Property POPID_ As Integer
        Get
            Return POPID
        End Get
        Set(value As Integer)
            POPID = value
        End Set
    End Property

    Property PROID_ As Integer
        Get
            Return PROID
        End Get
        Set(value As Integer)
            PROID = value
        End Set
    End Property

    Property POCID_ As Integer
        Get
            Return POCID
        End Get
        Set(value As Integer)
            POCID = value
        End Set
    End Property

    Property ODISCOUNT_ As Double
        Get
            Return ODISCOUNT
        End Get
        Set(value As Double)
            ODISCOUNT = value
        End Set
    End Property

    Property IDISCOUNT_ As Double
        Get
            Return IDISCOUNT
        End Get
        Set(value As Double)
            IDISCOUNT = value
        End Set
    End Property

    Property selectProonproduct_ As String
        Get
            Return selectProonproduct
        End Get
        Set(value As String)

        End Set
    End Property

    Property PRCID_ As Integer
        Get
            Return PRCID
        End Get
        Set(value As Integer)
            PRCID = value
        End Set
    End Property

    Property MTRGTID_ As Integer
        Get
            Return MTRGTID
        End Get
        Set(value As Integer)
            MTRGTID = value
        End Set
    End Property

    Property STRGTID_ As Integer
        Get
            Return STRGTID
        End Get
        Set(value As Integer)
            STRGTID = value
        End Set
    End Property

    Property SBRGTID_ As Integer
        Get
            Return SBRGTID
        End Get
        Set(value As Integer)
            SBRGTID = value
        End Set
    End Property

    Property F_PRO_ As Boolean
        Get
            Return F_PRO
        End Get
        Set(value As Boolean)
            If value = True Then
                F_PRO = 1
            Else
                F_PRO = 0
            End If
        End Set
    End Property

    Property OPDRC_ As Double
        Get
            Return OPDRC
        End Get
        Set(value As Double)
            OPDRC = value
        End Set
    End Property

    Property IPDRC_ As Double
        Get
            Return IPDRC
        End Get
        Set(value As Double)
            IPDRC = value
        End Set
    End Property

    Property STDATE_ As String
        Get
            Return STDATE
        End Get
        Set(value As String)
            STDATE = value
        End Set
    End Property

    Property ENDATE_ As String
        Get
            Return ENDATE
        End Get
        Set(value As String)
            ENDATE = value
        End Set
    End Property

    Property selectPrdprice_ As String
        Get
            Return selectPrdprice
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub ProoncontactCombobox(ByVal comboboxName As ComboBox)
        Dim proidData As DataTable
        proidData = connect.GetTable("SELECT a.`proid`, b.`proname` FROM prooncontact a JOIN maspromotion b ON a.proid = b.proid WHERE a.`status` = '1'")
        Try
            With comboboxName
                .DataSource = proidData
                .DisplayMember = "PRONAME"
                .ValueMember = "PROID"
                '.BindingContext = BindingContext
            End With
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub insertProonproduct()
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()
            'Dim dischargeID As Integer

            connect.ExecuteNonQuery("INSERT INTO proonproduct (proid, pocid, prdcode, odiscount, idiscount, status) VALUES ('" & PROID & "', '" & POCID & "', '" & PRDCODE & "', '" & ODISCOUNT & "', '" & IDISCOUNT & "', '" & STATUS & "')")
            'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
            'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
            'MsgBox("ท่านได้ทำการเพิ่มข้อมูลโปรโมชั่นเรียบร้อยแล้ว")
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
        End Try
        connect.Dispose()
        'connectlocal.Dispose()
    End Sub

    Public Sub editProonproduct()
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()

            connect.ExecuteNonQuery("UPDATE proonproduct SET odiscount = '" & ODISCOUNT & "', idiscount = '" & IDISCOUNT & "', status = '" & STATUS & "' WHERE popid = '" & POPID & "'")
            'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
            MsgBox("ท่านได้ทำการแก้ไขข้อมูลโปรโมชั่นเรียบร้อยแล้ว")
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
        End Try
        connect.Dispose()
        'connectlocal.Dispose()
    End Sub

    Public Sub insertPrdprice()
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()
            'Dim dischargeID As Integer

            connect.ExecuteNonQuery("INSERT INTO prdprice (prdcode, mtrgtid, strgtid, sbrgtid, proid, f_pro, opdrc, ipdprc, stdate, endate, status) VALUES ('" & PRDCODE & "', '" & MTRGTID & "', '" & STRGTID & "', '" & SBRGTID & "', '" & PROID & "', '" & F_PRO & "', '" & OPDRC & "', '" & IPDRC & "', '" & STDATE & "', '" & ENDATE & "', '" & STATUS & "')")
            'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
            'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
            'MsgBox("ท่านได้ทำการเพิ่มข้อมูลโปรโมชั่นเรียบร้อยแล้ว")
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
        End Try
        connect.Dispose()
        'connectlocal.Dispose()
    End Sub

    Public Sub editPrdprice()
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()

            connect.ExecuteNonQuery("UPDATE prdprice SET prdcode = '" & PRDCODE & "', mtrgtid = '" & MTRGTID & "', strgtid = '" & STRGTID & "', sbrgtid = '" & SBRGTID & "', proid = '" & PROID & "', f_pro = '" & F_PRO & "', opdrc = '" & OPDRC & "', ipdprc = '" & IPDRC & "', stdate = '" & STDATE & "', endate = '" & ENDATE & "', status = '" & STATUS & "' WHERE prcid = '" & PRCID & "'")
            'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
            MsgBox("ท่านได้ทำการแก้ไขข้อมูลโปรโมชั่นเรียบร้อยแล้ว")
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
        End Try
        connect.Dispose()
        'connectlocal.Dispose()
    End Sub
End Class
